<script type="text/javascript" src="/static/js/ws4redis.js"></script>
<script type="text/javascript">
	jQuery(document).ready(function($) {
    var ws4redis = WS4Redis({
        uri: 'ws://{{ SITE_DOMAIN }}/ws/{{ channel }}?subscribe-broadcast&publish-broadcast&echo',
        connecting: on_connecting,
        connected: on_connected,
        receive_message: receiveMessage,
        disconnected: on_disconnected,
        heartbeat_msg: '--heartbeat--'
    });

    // attach this function to an event handler on your site
    function sendMessage() {
        ws4redis.send_message('A message');
    }

    function on_connecting() {
        alert('Websocket is connecting...');
    }

    function on_connected() {
        ws4redis.send_message('Hello');
    }

    function on_disconnected(evt) {
        alert('Websocket was disconnected: ' + JSON.stringify(evt));
    }

    // receive a message though the websocket from the server
    function receiveMessage(msg) {
        alert('Message from Websocket: ' + msg);
        
    }
});
</script>